import utime
from usr.threading import Thread, EventSet

EVENT_1 = (1 << 0)
EVENT_2 = (1 << 1)
EVENT_ALL = 0xFFFF


eset = EventSet()


def t1_test_func(eset):
    while True:
        print("thread t1 sleep 10s")
        utime.sleep(10)
        print("thread t1 set event 1 and 2")
        eset.set(EVENT_1 | EVENT_2)
        utime.sleep(5)
        eset.clear(EVENT_1)
        print("thread t1 clear event 1")


def t2_test_func(eset):
    while True:
        print("thread t2 wait event 1 and 2")
        result = eset.wait(EVENT_1 | EVENT_2)
        print("thread t2 wait result: {}".format(result))
        utime.sleep(1)


t1 = Thread(target=t1_test_func, args=(eset, ))
t2 = Thread(target=t2_test_func, args=(eset, ))

t1.start()
t2.start()
